package org.zhangxiao.paladin2.common.util;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Setter
@Getter
public abstract class PageVO2<T> {
    //总记录数
    private long total;
    //总页数
    private long pages;
    //当前页
    private long pageNum;
    //每页的数量
    private long pageSize;
    //是否为第一页
    private boolean isFirstPage;
    //是否为最后一页
    private boolean isLastPage;
    //列表数据
    private List<T> list;

    @JsonIgnore
    private Page<T> page;

    public PageVO2() {
        IPage<T> page = this.getPage();
        this.total = page.getTotal();
        this.pages = page.getPages();
        this.pageNum = page.getCurrent();
        this.pageSize = page.getSize();
        this.isFirstPage = page.getCurrent() == 1;
        boolean isLastPage = false;
        if (page.getPages() == 0) {
            isLastPage = true;
        } else if (page.getPages() > 0 && page.getPages() <= page.getCurrent()) {
            isLastPage = true;
        }
        this.isLastPage = isLastPage;
        this.list = page.getRecords();
    }

    public abstract IPage<T> getPage();
}
